package com.Maykk.Demo05;

import java.util.Arrays;

/**
 * @ClassName: Demo01
 * @Description: TODO 可变参数
 * 可变参数实际是一个数组
 * 如果铍铜参数和可变参数结合使用的话，可变参数需要放到形参列表的最后
 * @Author: MaykkStar@163.com
 */
public class Demo01 {
    public static void main(String[] args) {
        System.out.println(mySum(1, 2));
        System.out.println(mySum(1, 2, 3));
        System.out.println(mySum(1, 2, 3, 4));
        show("123", 1, 2, 3, 5, 6, 7, 8, 9, 10);
    }

    public static void show(String str, int... a) {
        System.out.println(str);
        for (int i : a) {
            System.out.print(i + ", ");
        }

    }

    public static int mySum(int... a) {
        int sum = 0;
        for (int i = 0; i < a.length; i++) {
            sum += a[i];
        }
        return sum;

    }
}
